﻿using Coldairarrow.Business;
using Coldairarrow.Entity;
using Coldairarrow.Entity.BS_Lables;
using Coldairarrow.IBusiness.BS_Lables;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers
{
    [Route("/BS_Lables/[controller]/[action]")]
    public class BS_LableController : BaseApiController
    {
        #region DI

        public BS_LableController(IBS_LableBusiness BS_LableBus)
        {
            _BS_LableBus = BS_LableBus;
        }

        private IBS_LableBusiness _BS_LableBus { get; }

        #endregion DI

        #region 获取

        /// <summary>
        /// 后台--获取商品标签列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<BS_Lable>> GetDataList(PageInput<TSeachDTO> input)
        {
            return await _BS_LableBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 后台--获取商品标签详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<BS_Lable> GetTheData(IdInputDTO input)
        {
            return await _BS_LableBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 后台--根据分类或模糊获取标签下拉列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<object> GetsLableList(TSeachDTO input)
        {
            return await _BS_LableBus.GetLableList(input.Keyword);
        }

        #endregion 获取

        #region 提交

        /// <summary>
        /// 后台--保存/修改商品标签
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(BS_Lable data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _BS_LableBus.AddDataAsync(data);
            }
            else
            {
                await _BS_LableBus.UpdateDataAsync(data);
            }
        }

        /// <summary>
        /// 后台--删除商品标签
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _BS_LableBus.DeleteDataAsync(ids);
        }

        #endregion 提交
    }
}